package main

import (
	"encoding/json"
)

type User struct {
}

func NewUser() *User {
	return &User{}
}

// GetUserPhoneNumber 获取手机号
// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/phone-number/getPhoneNumber.html
func (u *User) GetUserPhoneNumber(code string, token string) (entity UserPhoneNumberResp, err error) {
	url := "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + token
	params := struct {
		Code string `json:"code"`
	}{code}

	b, err := json.Marshal(params)
	if err != nil {
		return
	}

	res, err := HttpPostJson(url, b)
	if err != nil {
		return
	}

	err = json.Unmarshal(res, &entity)

	return
}
